#!/usr/bin/env bash

## SCRIPT TO FIX SLIM RELEASES

## This script is a nasty bit of hackery.  Basically, instead of doing any kind
## of analysis, it solves the "erlang version mismatch" between a generated slim
## release and the installed erlang version.  Rather than using a scalpel and
## carefully upgrading scripts and regenerating the boot files, it activates
## "HULK SMASH MODE" to solve this problem:

## 1) It removes the releases directory
## 2) it clones nitrogen into /tmp
## 3) it generates a slim_release in /tmp/myapp
## 4) It moves the newly generated releases directory into our project's directory

## This is as inelegant as can possibly be done, but it works.


# so we can get back
home=`pwd`

# nasty: clone nitrogen and generate a slim release using the current version
# of erlang so we can just copy the releases directory. A little embarrassingly
# stupid.
mkdir -p /tmp/nitrogen
cd /tmp
git clone git://github.com/nitrogen/nitrogen
cd nitrogen
## The generated release doesn't need anything more, and slim_inets has the
## fewest dependencies to build and fetch (since dependencies don't do anything
## for our releases directory anyway)
make slim_inets

# back to project dir
cd $home
rm -fr releases
mv /tmp/myapp/releases .

# clean up
rm -fr /tmp/nitrogen
rm -fr /tmp/myapp
